package com.eaglefly.redis.scan;

import com.eaglefly.redis.core.DaoProxyFactory;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.Codec;
import org.springframework.beans.factory.FactoryBean;

/**
 * 功能：
 * 时间：2018/1/5 16:09
 *
 * @author zhaojinpeng
 */
public class DaoFactoryBean<T> implements FactoryBean<T> {

    private DaoProxyFactory daoProxyFactory;

    private Class<T> daoInterface;

    private RedissonClient redisson;

    private Class<T> superInterface;

    private String redisKey;

    private Codec codec;


    public DaoFactoryBean() {
    }

    public DaoFactoryBean(Class<T> daoInterface) {
        this.daoInterface = daoInterface;
    }


    @Override
    public T getObject() throws Exception {
        return daoProxyFactory.newInstance((Redisson) redisson, daoInterface, superInterface, redisKey, codec);
    }


    @Override
    public Class<T> getObjectType() {
        return this.daoInterface;
    }


    @Override
    public boolean isSingleton() {
        return true;
    }


    public void setDaoInterface(Class<T> daoInterface) {
        this.daoInterface = daoInterface;
    }


    public Class<T> getDaoInterface() {
        return daoInterface;
    }

    public DaoProxyFactory getDaoProxyFactory() {
        return daoProxyFactory;
    }

    public void setDaoProxyFactory(DaoProxyFactory daoProxyFactory) {
        this.daoProxyFactory = daoProxyFactory;
    }

    public RedissonClient getRedisson() {
        return redisson;
    }

    public void setRedisson(RedissonClient redisson) {
        this.redisson = redisson;
    }

    public Class<T> getSuperInterface() {
        return superInterface;
    }

    public void setSuperInterface(Class<T> superInterface) {
        this.superInterface = superInterface;
    }

    public String getRedisKey() {
        return redisKey;
    }

    public void setRedisKey(String redisKey) {
        this.redisKey = redisKey;
    }

    public Codec getCodec() {
        return codec;
    }

    public void setCodec(Codec codec) {
        this.codec = codec;
    }
}
